package com.william.jdbcplus.core.toolkit;

import com.william.jdbcplus.core.parser.ISqlParser;
import com.william.jdbcplus.core.parser.JsqlParserCount;
import com.william.jdbcplus.core.parser.SqlInfo;

/**
 * sql count解析器
 *
 * @author niliwei
 */
public class SqlParserUtils {
    private static ISqlParser COUNT_SQL_PARSER = null;

    public SqlParserUtils() {
    }

    public static String getOriginalCountSql(String originalSql) {
        return String.format("SELECT COUNT(1) FROM ( %s ) TOTAL", originalSql);
    }

    public static SqlInfo getOptimizeCountSql(String originalSql) {
        if (null == COUNT_SQL_PARSER) {
            COUNT_SQL_PARSER = new JsqlParserCount();
        }
        return COUNT_SQL_PARSER.parser(originalSql);
    }
}

